<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" id="html">
    <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <base href="<?= base_url(1); ?>" />
        <link type="text/css" href="css/main.css?v=<?= $config['version'] ?>" rel="stylesheet" />
        <style type="text/css">
            #searchfloat {position:absolute;top:40px;right:20px;background:#F7F0A0;padding:10px;}
            .coolbg {margin-bottom:5px;}
            .tablegrid tr td.act1 {width:10%;}
            .tablegrid {height:95%;}
            #saved {position: relative;}
            #saved_sql {position:absolute;bottom:0;height:300px;background:#F7F0A0;width:100%;overflow:auto;display:none;}
            #saved_sql li {display:block;clear:both;width:100%;float:left;line-height:18px;padding:1px 0}
            #saved_sql li a{float:left;text-decoration: none;display:block;padding:0 5px;}
            #saved_sql li i{display:none;float:left;color:#06f;font-size: 14px;font-style: normal;margin-left:2px;line-height:18px;}
            #saved_sql li:hover{background:#fff;}
            #saved_sql li:hover i{display:block;cursor:pointer;}
        </style>
    </head>
    <body>
        <?php include(VIEWPATH . 'common/main_header.php'); ?>
        <div id="searchfloat">
            <form action="<?= site_url('general/database/do_query') ?>" method="post" name="infoform" target="resultframe">
                <input type='hidden' name='do_action' value='viewinfo' />
                <div style="float:left;">
                    <select id="tablename" name="tablename[]" multiple="multiple" style="width:200px;height:180px;margin:0;padding:0;">
                        <?php foreach ($tables as $m => $n) { ?><option value="<?= $n['Name'] ?>" <?php if ($m % 2 == 0) { ?>style="background:#f7f7f7;"<?php } ?> title="<?= translate('GENERAL_DATABASE_COMMENT') ?>:<?= $n['Comment'] ?>&#13<?= translate('GENERAL_DATABASE_SIZE') ?>:<?= format_filesize($n['Data_length']) ?>&#13<?= translate('GENERAL_DATABASE_INDEX') ?>:<?= format_filesize($n['Index_length']) ?>&#13<?= translate('GENERAL_DATABASE_UPDATE') ?>:<?= $n['Update_time'] ?>"><?= $n['Name'] ?>(<?= $n['Rows'] ?>)</option><?php } ?>
                        <option disabled><?= translate('GENERAL_DATABASE_SUM_TABLES', count($tables)) ?></option>
                        <option disabled><?= translate('GENERAL_DATABASE_SUM_RECORDS', $tables_data_count) ?></option>
                        <option disabled><?= translate('GENERAL_DATABASE_SUM_SIZES', format_filesize($tables_data_length)) ?></option>
                        <option disabled><?= translate('GENERAL_DATABASE_SUM_INDEXS', format_filesize($tables_index_length)) ?></option>
                    </select>
                </div>
                <div style="float:left;margin-left:8px;">
                    <input type="submit" name="submit3" value="<?= translate('GENERAL_DATABASE_READ_STRUCT') ?>" class="coolbg np" onClick="this.form.do_action.value = 'view_info';"/><br />
                    <input type="submit" name="submit7" value="<?= translate('GENERAL_DATABASE_READ_DATA') ?>" class="coolbg np" onClick="this.form.do_action.value = 'view_data';"/><br />
                    <input type="submit" name="submit1" value="<?= translate('GENERAL_DATABASE_OPTIMIZE_SELECT') ?>" class="coolbg np" onClick="this.form.do_action.value = 'optimize';" /><br />
                    <input type="submit" name="submit2" value="<?= translate('GENERAL_DATABASE_REPAIR_SELECT') ?>" class="coolbg np" onClick="this.form.do_action.value = 'repair';"/><br />
                    <input type="submit" name="submit5" value="<?= translate('GENERAL_DATABASE_OPTIMIZE_ALL') ?>" class="coolbg np" onClick="this.form.do_action.value = 'optimize_all';" /><br />
                    <input type="submit" name="submit6" value="<?= translate('GENERAL_DATABASE_REPAIR_ALL') ?>" class="coolbg np" onClick="this.form.do_action.value = 'repair_all';"/>
                </div>
            </form>
        </div>
        <form action="<?= site_url('general/database/do_query') ?>" method="post" id="sqlexecute" name="form1" target="resultframe">
            <table width="100%" border="0" cellspacing="1" cellpadding="0" class="tablegrid tableedit">
                <tr><th colspan="2" height="20"><?= $title ?></th></tr>
                <tr>
                    <td valign="top" style="height:100%;"><?= translate('RESULT') ?>：</td>
                    <td style="height:100%;">
                        <iframe name="resultframe" frameborder="0" id="resultframe" width="100%" height="100%"></iframe>
                        <div id="saved">
                            <div id="saved_sql">
                                <?php
                                foreach ($saved_sql as $m => $n) {
                                    echo "<li><a href='javascript:;' title=''>{$n}</a><i rel='{$m}'>×</i></li>";
                                }
                                ?>
                            </div>
                        </div>
                    </td>
                </tr>
                <input type='hidden' name='do_action' value='query' />
                <tr>
                    <td valign="top"><?= translate('GENERAL_DATABASE_COMMAND_LINE') ?>：<br /><a href="javascript:;" id="showsaved"><?= translate('GENERAL_DATABASE_COMMAND_SAVED') ?></a>　</td>
                    <td height="118"><textarea name="sqlquery" cols="60" rows="10" id="sqlquery" style="width:98%;"></textarea></td>
                </tr>
                <tr>
                    <td>　</td>
                    <td style="text-align: left;">
                        <input type="submit" value="<?= translate('EXECUTE') ?>" /> 
                        <input type="reset" value="<?= translate('RESET') ?>" /> 
                        <input type="button" id="savesql" value="<?= translate('SAVE') ?>" /> 
                        <?= translate('SYNC') ?>: <?= str_replace(' selected="selected"', '', $arealist); ?>
                    </td>
                </tr>
            </table>
        </form>
        <script type="text/javascript">
                        $(function() {
                            $("#searchfloat").live("dblclick", function() {
                                $("div", this).toggle();
                            });
                            $(window).resize(function() {
                                $("#resultframe").height($(window).height() - 250);
                            });
                            //提交时检查是否有删除或清空操作
                            $("#sqlexecute").submit(function() {
                                var v = $("#sqlquery").val().toLowerCase();
                                if ((v.indexOf("delete ") >= 0 || v.indexOf("truncate ") >= 0) && !confirm("<?= translate('GENERAL_DATABASE_VIEW_CONFIIRM') ?>")) {
                                    return false;
                                }
                            });
                            $("#showsaved").live('click', function() {
                                $("#saved_sql").slideToggle();
                            });
                            $("#savesql").live('click', function() {
                                var s = $("#sqlquery").val();
                                if (s == '')
                                    return alert("<?= translate('GENERAL_DATABASE_NO_EMPTY') ?>");
                                $.ajax({
                                    url: '<?= site_url('general/database/save_query') ?>',
                                    type: 'POST',
                                    data: {sql: s},
                                    success: function(ret) {
                                        var rel = $("#saved_sql li:last i").size() ? parseInt($("#saved_sql li:last i").attr("rel")) + 1 : 0;
                                        $("<li><a href='javascript:;'>" + s + "</a><i rel='" + rel + "'>×</i>").prependTo($("#saved_sql"));
                                        SG.admin.success("<?= translate('C_TIPS_SUCCESS_TEXT') ?>");
                                    },
                                    error: function(ret) {
                                        SG.admin.failure("<?= translate('C_TIPS_ERROR_TEXT') ?>:" + ret);
                                    }
                                })
                            });
                            $("#saved_sql a").live("click", function() {
                                $("#sqlquery").val($(this).text());
                            });
                            $("#saved_sql li i").live("click", function() {
                                var _this = this;
                                $.ajax({
                                    url: "<?= site_url('general/database/del_query') ?>",
                                    type: 'POST',
                                    data: {index: $(this).attr("rel")},
                                    success: function(ret) {
                                        var p = $(_this).parent().parent();
                                        $(_this).parent().remove();
                                        $("li", p).each(function(i) {
                                            $("i", this).attr("rel", i);
                                        });
                                        SG.admin.success("<?= translate('C_TIPS_SUCCESS_TEXT') ?>");
                                    }, error: function(ret) {
                                        SG.admin.failure("<?= translate('C_TIPS_ERROR_TEXT') ?>:" + ret);
                                    }
                                })
                            });
                            $(window).resize();
                        });
        </script>
    </body>
</html>